﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;

namespace Ukagaka.Named.Ghost.Shiori.Sample
{
	/// <summary>
	/// サンプルプログラムを表現します
	/// </summary>
	class Program
	{
		private ShioriConnection Connection;

		private bool IsUnloaded;

		private void Run( )
		{
			Connection = new ShioriConnection( Console.OpenStandardInput( ), Console.OpenStandardOutput( ) );
			{
				Connection.Load += Connection_Load;
				Connection.Request += Connection_Request;
				Connection.Unload += Connection_Unload;
			}

			Connection.Touch( );

			while ( !IsUnloaded )
			{
				Thread.Sleep( 1600 );
			}
		}

		private void Connection_Load( object sender, EventArgs e )
		{
			Debug.WriteLine( "Load" );
		}

		private void Connection_Request( object sender, ShioriEventArgs e )
		{
			Debug.WriteLine( e.Request );
		}

		private void Connection_Unload( object sender, EventArgs e )
		{
			Debug.WriteLine( "Unload" );

			IsUnloaded = true;
		}

		/// <summary>
		/// サンプルプログラムのメインルーチンです
		/// </summary>
		/// <param name="args">サンプルプログラムの起動引数</param>
		static void Main( string[ ] args )
		{
			var program = new Program( );
			program.Run( );
		}
	}
}
